﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncReferenceUniv.ReferenceUniverseLogic
{
    public class ReferenceUniverseOrchestrator
    {
        private readonly ReferenceUniverseCddbQuery referenceUniverseCddbQuery;
        private readonly ReferenceUniverseCommand referenceUniverseCommand;
        

        public ReferenceUniverseOrchestrator(
            ReferenceUniverseCddbQuery referenceUniverseCddbQuery,
            ReferenceUniverseCommand referenceUniverseCommand)
        {
            this.referenceUniverseCddbQuery = referenceUniverseCddbQuery;
            this.referenceUniverseCommand = referenceUniverseCommand;
            
        }

        public async Task<int> OrchestrateAsync()
        {
            var referenceUniverseEntities = referenceUniverseCddbQuery.Get();

            await referenceUniverseCommand.DeleteRecordsAsync();
            await referenceUniverseCommand.InsertRecordsAsync(referenceUniverseEntities);
            return referenceUniverseEntities.Count;
        }
    }
}
